#include <iostream>

using namespace std;
using ll=long long;
const int N=4e5+10;

char s[N];
ll a[N];
int main()
{
	ll n,m;
	ll ret=0;
	cin>>n>>m;
	scanf("%s",s);
	for(int i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
		s[i+n]=s[i];
		a[i+n]=a[i];
		ret+=a[i];
	}
	
	int p=0;
	while(p<n && s[p]==s[p+1])
		p++;
	if(p<n)
	{
		for(int i=p+1;i<=n;i++)
		{
			int j=i;
			ll sum=0;
			while(j<=n+p && s[i]==s[j])
			{
				sum+=a[j];
				j++;
			}
			if(s[i]=='L')
			{
				sum-=a[i];
			}
			else{
				
				sum-=a[j-1];
			}
			i=j-1;
			ret-=min(sum,m);
		}
	}
	cout<<ret<<endl;
	
	return 0;
}
